---
title: hexColor
description: Creates a hex color validation action.
source: /actions/hexColor/hexColor.ts
contributors:
  - fabian-hiller
  - ariskemper
---

import { ApiList, Property } from '~/components';
import { properties } from './properties';

# hexColor

Creates a [hex color](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) validation action.

```ts
const Action = v.hexColor<TInput, TMessage>(message);
```

## Generics

- `TInput` <Property {...properties.TInput} />
- `TMessage` <Property {...properties.TMessage} />

## Parameters

- `message` <Property {...properties.message} />

### Explanation

With `hexColor` you can validate the formatting of a string. If the input is not a hex color, you can use `message` to customize the error message.

## Returns

- `Action` <Property {...properties.Action} />

## Examples

The following examples show how `hexColor` can be used.

### Hex color schema

Schema to validate a hex color.

```ts
const HexColorSchema = v.pipe(
  v.string(),
  v.hexColor('The hex color is badly formatted.')
);
```

## Related

The following APIs can be combined with `hexColor`.

### Schemas

<ApiList items={['any', 'custom', 'string']} />

### Methods

<ApiList items={['pipe']} />

### Utils

<ApiList items={['isOfKind', 'isOfType']} />
